package cn.edu.nuc.carsystem.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import cn.edu.nuc.carsystem.dto.PageInfo;
import cn.edu.nuc.carsystem.model.Bank;
import cn.edu.nuc.carsystem.model.Car;
import cn.edu.nuc.carsystem.model.City;
import cn.edu.nuc.carsystem.model.Conrtuny;
import cn.edu.nuc.carsystem.model.Custome;
import cn.edu.nuc.carsystem.service.interfaces.BankService;
import cn.edu.nuc.carsystem.service.interfaces.CarService;
import cn.edu.nuc.carsystem.service.interfaces.CityService;
/**
 * 银行controller
 * @author 杨晓庆
 *
 */
@RequestMapping("/custome/car")
@Controller
public class CarController {
   @Autowired
   private CarService carService;
   /**
    * 添加车辆
    * @param city
    * @return
    */
   @RequestMapping(value="/insert",method=RequestMethod.POST)
	public String insert(Car car){
    Integer count=carService.insert(car);
    if(count>0){
	   return "redirect:/custome/car/find";
    }
    else
       return "/costume/car/addCar";
   }
   /**
    * 跳转添加银行页面
    * @param city
    * @return
    */
   @RequestMapping(value="/addCar",method=RequestMethod.GET)
	public String addBank(Car car){
   
       return "custome/addcar";
   }
   /**
    * 查询车辆
    * @param current
    * @return
    */
   @RequestMapping(value="/find",method=RequestMethod.GET)
  	public ModelAndView find(HttpSession session){
	   Custome custome=(Custome) session.getAttribute("custome");
      ModelAndView model=new ModelAndView("custome/detailcar");
      Car car=carService.selectByPrimaryCustomeId(custome.getCustomeid());
      model.addObject("car",car);
      System.out.println("car"+car);
      System.out.println("custome"+custome);
  	  return model;
  	}

}
